<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { CrewEnterprise, CrewEnterpriseCheck } from "@/http/api";
import tableBigImg from "@/components/public/tableBigImg.vue";

export default {
  components: { outMain, tableBigImg },
  name: "",
  data() {
    return {
      tableData: [],
      queryData: {
        enterprise_mobile: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    questCheck(data) {
      CrewEnterpriseCheck(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
        }
      });
    },
    checkStatus(row, type) {
      let str = type == 1 ? "恢复" : "禁用";
      ElMessageBox.confirm(`确定${str}选择的小程序企业账号吗?`, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = {
          enterprise_id: row.enterprise_id,
          enterprise_status: type,
        };
        this.questCheck(data);
      });
    },
    serchFn() {
      this.queryData.page = 1;
      this.getData();
    },
    getData() {
      CrewEnterprise(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  async created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>小程序企业列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.enterprise_mobile"
                placeholder="请输入联系电话"
              />
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="comName"
          width="100"
          show-overflow-tooltip
          label="企业logo"
        >
          <template #default="{ row }">
            <img class="userImg" :src="row.enterprise_logo" />
          </template>
        </el-table-column>

        <el-table-column
          prop="enterprise_name"
          show-overflow-tooltip
          width="200"
          label="企业名称"
        />
        <el-table-column
          prop="nick_name"
          width="150"
          show-overflow-tooltip
          label="小程序账号"
        />
        <el-table-column
          show-overflow-tooltip
          width="100"
          prop="enterprise_person"
          label="联系人"
        />
        <el-table-column
          prop="enterprise_mobile"
          width="130"
          show-overflow-tooltip
          label="联系电话"
        />
        <el-table-column width="80" show-overflow-tooltip label="账号状态">
          <template #default="{ row }">
            <el-tag v-if="row.enterprise_status == 1" type="success"
              >正常</el-tag
            >
            <el-tag v-if="row.enterprise_status == 2" type="danger"
              >禁用</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="enterprise_address"
          show-overflow-tooltip
          label="企业地址"
        />
        <el-table-column
          prop="create_time"
          width="170"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column label="营业执照">
          <template #default="{ row }"
            ><tableBigImg
              v-if="row.enterprise_file"
              :propImg="row.enterprise_file"
              :src="row.enterprise_file"
            ></tableBigImg
          ></template>
        </el-table-column>
        <el-table-column prop="Name" width="60" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="blueText ctrlText"
                v-if="row.enterprise_status === 2"
                @click="checkStatus(row, 1)"
              >
                恢复
              </div>
              <div
                class="redText ctrlText"
                v-if="row.enterprise_status === 1"
                @click="checkStatus(row, 2)"
              >
                禁用
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
